const arr = [1, 2, 3, 4]

Array.prototype.my_forEach = function (callback) {
    for (let i = 0; i < this.length; i++) {
        callback(this[i], i, this)
    }
}
Array.prototype.my_map = function (callback) {
    const newArr = []
    for (let i = 0; i < this.length; i++) {
        callback(this[i], i, this)
        newArr.push(this[i])
    }
    return newArr
}
Array.prototype.myFilter = function (callback) {
    const newArr = []
    for (let i = 0; i < this.length; i++) {
        callback(this[i], i, this)
        if (callback(this[i], i, this)) {
            newArr.push(this[i])
        }
    }
    return newArr
}
Array.prototype.myEvery = function (callback) {
    for (let i = 0; i < this.length; i++) {
        if (!callback(this[i], i, this)) {
            return false
        }
    }
    return true
}
Array.prototype.mySome = function (callback) {
    for (let i = 0; i < this.length; i++) {
        if (callback(this[i], i, this)) {
            return true
        }
    }
    return false
}
Array.prototype.myreduce = function (callback, ...arg) {
    let pre,start = 0;
    arg.length ? pre = arg[0] : (pre = this[0],start=1)
    for (let i = start; i < this.length; i++) {
        pre = callback(pre,this[i],i,this)
    }
    return pre
}
// const arr2 = arr.my_map((item,index,arr)=>{
//     console.log(item,index,arr)
// })
// // arr.my_forEach((item,index,arr)=>{
// //     console.log(item,index,arr)
// // })
// console.log(arr2)
// const arr3=arr.myFilter((item,index,arr)=>{
//     console.log(item,index,arr)
//     return item > 1
// })
// console.log(arr3)
const res = arr.myEvery((item, index, arr) => {
    console.log(item, index, arr)
    return item > 1
})
console.log(res)
